﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace BudgetKeeper
{
    class BudgetPost
    {
        public int Id { get; set; }
        public string Name { get; set; }
        public double StartTotal { get; set; }
        public double RemainingTotal { get; set; }
        private List<Expense> ExpensesList;

        /// <summary>
        /// Initiates a new budget post
        /// </summary>
        /// <param name="name">Name of post</param>
        /// <param name="startingTotal">Starting sum</param>
        public BudgetPost(int id, string name, double startingTotal)
        {
            Id = id;
            Name = name;
            StartTotal = startingTotal;
            RemainingTotal = startingTotal;
            ExpensesList = new List<Expense>();
        }

        /// <summary>
        /// Withdraws money from the budget post
        /// </summary>
        /// <param name="name">Reason for withdrawal</param>
        /// <param name="sum">Sum of expense</param>
        /// <param name="date">Date of expense</param>
        public void AddExpense(string name, double sum, string date)
        {
            RemainingTotal -= sum;
            ExpensesList.Add(new Expense(name, sum, date));
        }

        public double GetExpensesTotal()
        {
            double sum = 0;
            foreach (Expense exp in ExpensesList)
            {
                sum += exp.Sum;
            }
            return sum;
        }
    }
}
